package pluginMain;

import java.util.HashSet;
import java.util.Set;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class EffectCotainer {
	public final static boolean VICTIM = true;
	public final static boolean DAMAGER = false;
	private LivingEntity v, d;
	private Set<PotionEffect> victim_Potion;
	private Set<PotionEffect> damager_Potion;
	private double damage;
	private double pureDamage;
	private EntityDamageByEntityEvent damageEvent;

	public EffectCotainer(EntityDamageByEntityEvent e, double baseDamage) {
		v = Lore.getDamager(e);
		d = Lore.getEntity(e);
		victim_Potion = new HashSet<PotionEffect>();
		damager_Potion = new HashSet<PotionEffect>();
		damageEvent = e;
		damage = baseDamage;
	}

	public void removePotionEffect(boolean isVictim, PotionEffectType type) {
		Set<PotionEffect> target;
		if (isVictim)
			target = victim_Potion;
		else
			target = damager_Potion;
		for (PotionEffect pe : target) {
			if (pe.getType() == type) {
				target.remove(pe);
			}
		}
	}

	public void addPotionEffect(boolean isVictim, PotionEffect effect) {
		if (isVictim)
			victim_Potion.add(effect);
		else
			damager_Potion.add(effect);
	}

	public void addDamage(double value) {
		damage += value;
	}

	public void addPureDamage(double value) {
		pureDamage += value;
	}
	
	public double getPureDamage(){
		return pureDamage;
	}
	
	public double getDamage() {
		return damage;
	}

	public void doFianlDamage() {
		if(victim_Potion.size() > 0 && v != null && !v.equals(null))v.addPotionEffects(victim_Potion);
		if(damager_Potion.size() > 0 && d != null && !d.equals(null)) d.addPotionEffects(damager_Potion);
		
		//v.setHealth(v.getHealth() - pureDamage);
		damageEvent.setDamage(damage);

	}

}
